package com.zjs.mq.kafka;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Description 消息接收者
 * @Author zhu
 * @Date 2020/2/25 15:18
 * @Version 1.0
 */
@Slf4j
@Component
public class KafkaReceiver {

    @KafkaListener(topics = {"hello"})
    public void listen(ConsumerRecord<?, ?> record) {
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            log.info("1----------------- record =" + record);
            log.info("1------------------ message =" + message);
        }
    }
}
